package com.xiaoxu.privatechat.dao.common;

import com.xiaoxu.privatechat.entity.common.AccountGroupMember;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @description 聊天会话数据库操作层
 * @date 2023/2/13
 * @author xiaoxu
 */
@Repository
public interface AccountGroupMemberDao extends JpaRepository<AccountGroupMember, Long> {

	/**
	 * @description 根据群id查找群成员
	 * @param id 群id
	 * @return List<AccountGroupMember>
	 */
	List<AccountGroupMember> findByAccountGroupId(Long id);

	/**
	 * @description  根据群成员id查找群成员
	 * @param id 群成员id
	 * @return List<AccountGroupMember>
	 */
	List<AccountGroupMember> findByMemberId(Long id);

	/**
	 * @description 根据群成员id和群id查找群成员
	 * @param accountGroupId 群id
	 * @param memberId 成员id
	 * @return AccountGroupMember
	 */
	AccountGroupMember findByAccountGroupIdAndMemberId(Long accountGroupId,Long memberId);

	/**
	 * @description 根据群id删除群成员
	 * @param accountGroupId 群成员id
	 */
	@Transactional
	void deleteByAccountGroupId(Long accountGroupId);

}
